﻿<%@ Page Title="" Language="C#" MasterPageFile="~/web/common/admin_common.Master"
    AutoEventWireup="true" CodeBehind="Add.aspx.cs" Inherits="shop.web.view_admin.goods.Add" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <title>添加商品</title>   
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
    <div class="fly-panel" pad20 style="padding-top: 5px;">
        <div class="layui-form layui-form-pane">
            <div class="layui-tab layui-tab-brief" lay-filter="user">
                <ul class="layui-tab-title">
                    <li class="layui-this">添加商品</li>
                </ul>
                <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">

                    <div class="layui-tab-item layui-show">
                        <form method="post" action="/handler/GoodsHandler.ashx?method=add" enctype="multipart/form-data">
                            <input type="hidden" name="method" value="add" />
                            <div class="layui-form-item">
                                <label for="L_name" class="layui-form-label">
                                    商品名称</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_name" name="name" required lay-verify="required" placeholder="商品名称"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>
                            <div class="layui-form-item">
                                <label for="L_price" class="layui-form-label">
                                    商品价格</label>
                                <div class="layui-input-inline">
                                    <input type="text" id="L_price" name="price" required lay-verify="required" placeholder="商品价格"
                                        autocomplete="off" class="layui-input">
                                </div>
                            </div>

                            <div class="layui-form-item layui-form-text">
                                <label class="layui-form-label">请填写描述</label>
                                <div class="layui-input-block">
                                    <textarea placeholder="请输入内容" class="layui-textarea" name="description"></textarea>
                                </div>
                            </div>

                            <div class="layui-inline  layui-form-item">
                                <label class="layui-form-label">
                                    商品类别
                                </label>
                                <div class="layui-input-block catagory">
                                    <select lay-verify="required" name="catagoryId" >
                                        <option></option>
                                        <%foreach (var catagory in catagoryList)
                                            {
                                        %>

                                        <option value="<%=catagory.Id %>"><%=catagory.Name %></option>
                                        <%
                                            }
                                        %>
                                    </select>
                                </div>
                            </div>

                           <%-- <div class="layui-form-item">
                                <div id="description"></div>
                            </div>--%>
                            <%-- <div class="layui-form-item">
                                <label  class="layui-btn" id="uploadImg">
                                    <input type="file" name="name" value="" style='width:0;opacity:0;filter:alpha(opacity=0);'/>
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </label>
                            </div>--%>
                            <div class="layui-form-item">
                                <button type="button" class="layui-btn" id="uploadImg">
                                    <i class="layui-icon">&#xe67c;</i>上传图片
                                </button>
                            </div>

                            <div class="layui-form-item">
                                <button class="layui-btn add" type="button">
                                    立即发布

                                </button>
                            </div>
                        </form>
                        <%-- <form action="/handler/ImageUpload.ashx" method="post" enctype="multipart/form-data">
                        
                            <button type="submit" class="layui-btn" id="uploadImg">

                                <i class="layui-icon">&#xe67c;</i>上传图片
                            </button>

                        </form>--%>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="/web/resource/wangEditor/wangEditor.min.js"></script>
    <script src="../../resource/plugin/jquery.form.js"></script>

    <script>  
        //          var E = window.wangEditor
        //var editor = new E('#description')
        ////// 或者 var editor = new E( document.getElementById('editor') )
        //editor.create()
        //layui.use('form', function () {
        //    var form = layui.form;
        //})
        var imageId = 0;
        //上传图片
        layui.use('upload', function () {
            var upload = layui.upload;

            //执行实例
            var uploadInst = upload.render({
                elem: '#uploadImg' //绑定元素
                , url: '/handler/UploadImageHandler.ashx' //上传接口
                , done: function (data) {
                    //上传完毕回调
                    console.log(data)
                    layer.msg("上传图片成功！", { icon: 6 })
                    //var image = JSON.parse(data); //由JSON字符串转换为JSON对象

                    imageId = data.Data.Id;

                }
                , error: function (data) {
                    //请求异常回调
                    layer.msg("上传图片失败！", { icon: 2 })
                    console.log(data)
                }
            });
        });
       
   
      

        $(".add").click(function () {
            $.ajax({
                url: $('form').attr('action'),
                type: "post",
                data: $("form").serialize() + '&imageId=' + imageId,
                success: function (data) {
                    console.log($("form").serialize() + '&imageId=' + imageId)

                    console.log(data)
                    var obj = JSON.parse(data);
                    //layer.msg(obj.ErrorCode, { icon: 6 });
                    if (obj.ErrorCode == 0) {
                        console.log(obj.Message)
                        //成功
                        layer.msg(obj.Message, { icon: 6 });
                        //layer.msg('成功', { icon: 6 });


                    } else {
                        layer.msg(obj.Message, { icon: 2 })

                    }
                }
            })
            //layer.msg('成功', { icon: 6 });
            //$("from").ajaxSubmit({
            //    url: $('form').attr('action'), //上传文件的路径   
            //    type: 'post',
            //    success: function (data) {
            //        console.log(data);
            //        layer.msg('成功', { icon: 6 });
            //        //....             //异步上传成功之后的操作
            //    },
            //    error: function (data) {
            //         console.log(data);
            //    }
            //})
        })


        //})
    </script>
</asp:Content>
